package com.elink.enginerring.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elink.enginerring.common.ErrorType;
import com.elink.enginerring.dao.LabelMapper;
import com.elink.enginerring.domain.Label;
import com.elink.enginerring.service.LabelService;
import com.elink.enginerring.util.JSONUtil;

@Service
public class LabelServiceImpl implements LabelService {
	@Autowired
	private LabelMapper labelMapper;

	@Override
	public Map<String, Object> add(String labels,String userId) {

		List<Label> labelList = new ArrayList<Label>();
		for (String label : labels.split(",")) {
			Label l = new Label();
			l.setLabelName(label);
			l.setUserId(userId);
			labelList.add(l);
		}
		labelMapper.insertBatch(labelList);
		return JSONUtil.getJSON(ErrorType.SUCCESS,labelMapper.select(labels,userId,labelList.size()));
	}
}
